//
//  ChooseTaoCanCell.m
//  XDBaseFrameWork
//
//  Created by XD-XY on 10/22/14.
//  Copyright (c) 2014 XD-XY. All rights reserved.
//

#import "ChooseTaoCanCell.h"

@implementation ChooseTaoCanCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self makeViews];
    }
    return self;
}

-(void)makeViews
{
    UIImageView * xuxian = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, .5f)];
    xuxian.image = LOADIMAGE(@"xuxian_long@2x");
    [self.contentView addSubview:xuxian];
    
    self.typeLB = [UILabel initLabelText:@"" andRect:CGRectMake(0, 0,70,46) andBackGroudColor:mClearColor andTextFont:[UIFont systemFontOfSize:14] andTextColor:UIColorFromRGB(0x4a4a4a) andTextAlignment:NSTextAlignmentCenter];
    
    self.mScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(70, 0, UI_SCREEN_WIDTH-70,46)];
    _mScrollView.contentSize = CGSizeMake(_mScrollView.frame.size.width,46);
    
    self.firstBtn = [UIButton initButton:CGRectMake(20,9,60,28.5) btnNorImage:[UIImage imageNamed:@"choosetaocan_nor@2x"] btnDisableBtn:[UIImage imageNamed:@"choosetaocan_dis@2x"] btnTitle:@"" titleNorColor:UIColorFromRGB(0x4a4a4a) titleSelectColor:UIColorFromRGB(0x4a4a4a) titleFont:[UIFont systemFontOfSize:12.5]];
    
//    [_firstBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//    [_firstBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
    
    [_firstBtn setTitleColor:UIColorFromRGB(0x8c8c8c) forState:UIControlStateDisabled];
    [_firstBtn setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateSelected];
    [_firstBtn setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateHighlighted];
    _firstBtn.adjustsImageWhenDisabled =NO;
    _firstBtn.adjustsImageWhenHighlighted =NO;
    
    self.secondBtn = [UIButton initButton:CGRectMake(20+89.5-14.5,9,60,28.5) btnNorImage:LOADIMAGE(@"choosetaocan_nor@2x") btnDisableBtn:LOADIMAGE(@"choosetaocan_dis@2x") btnTitle:@"" titleNorColor:UIColorFromRGB(0x4a4a4a) titleSelectColor:UIColorFromRGB(0x4a4a4a) titleFont:[UIFont systemFontOfSize:12.5]];
    
    
    [_secondBtn setTitleColor:UIColorFromRGB(0x8c8c8c) forState:UIControlStateDisabled];
    [_secondBtn setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateSelected];
    [_secondBtn setBackgroundImage:LOADIMAGE(@"choosetaocan_sel@2x") forState:UIControlStateHighlighted];
    _secondBtn.adjustsImageWhenDisabled =NO;
    _secondBtn.adjustsImageWhenHighlighted =NO;
    


    self.thirdBtn = [UIButton initButton:CGRectMake(20+2*(89.5-14.5),9,60,28.5) btnNorImage:LOADIMAGE(@"choosetaocan_nor@2x") btnDisableBtn:LOADIMAGE(@"choosetaocan_sel@2x") btnTitle:@"" titleNorColor:UIColorFromRGB(0x4a4a4a) titleSelectColor:UIColorFromRGB(0x4a4a4a) titleFont:[UIFont systemFontOfSize:13]];

    _thirdBtn.hidden = YES;
    
//    [_thirdBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//    [_thirdBtn setTitleColor:[UIColor redColor] forState:UIControlStateSelected];

    
    [_mScrollView addSubview:_firstBtn];
    [_mScrollView addSubview:_secondBtn];
    [_mScrollView addSubview:_thirdBtn];
    
    [self addSubview:_typeLB];
    [self addSubview:_mScrollView];
    
    [_firstBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_secondBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_thirdBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    _firstBtn.tag = 1000;
    _secondBtn.tag = 1001;
    _thirdBtn.tag = 1002;
    
}

-(void)setDataArray:(NSArray *)dataArray
{
    if (_dataArray){
        _dataArray = nil;
    }
    _dataArray = [[NSArray alloc] initWithArray:dataArray];
    [_firstBtn setTitle:[_dataArray firstObject] forState:UIControlStateNormal];
    [_secondBtn setTitle:[_dataArray objectAtIndex:1] forState:UIControlStateNormal];
    [_thirdBtn setTitle:[_dataArray lastObject] forState:UIControlStateNormal];
    
    _firstBtn.enabled = YES;
    _secondBtn.enabled = YES;
    _thirdBtn.enabled = YES;
    
    _firstBtn.selected = NO;
    _secondBtn.selected = NO;
    _thirdBtn.selected = NO;
    
}

-(void)buttonClick:(UIButton *)button
{
    if (button.isSelected){
        return;
    }
    if (_firstBtn.enabled){
        _firstBtn.selected = button.tag == _firstBtn.tag?YES:NO;
    }
    if (_secondBtn.enabled){
        _secondBtn.selected = button.tag == _secondBtn.tag?YES:NO;
    }
    if (_thirdBtn.enabled){
        _thirdBtn.selected = button.tag == _thirdBtn.tag?YES:NO;
    }
    
    if ([self.typeLB.text isEqualToString:@"拍摄地点"]){  //kind =1
        [_delegate choosekind:1 andType:button.tag-1000+1];
    }else if ([self.typeLB.text isEqualToString:@"服装造型"]){  //kind =2
        [_delegate choosekind:2 andType:button.tag-1000+1];
    }else if ([self.typeLB.text isEqualToString:@"相册"]){  //kind =3
        if(button.tag == 1000){
            [_delegate choosekind:3 andType:1];
        }else{
            [_delegate choosekind:3 andType:0];
        }
    }
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
